define(function (require,exports,module) {
    var myPub = require('./public');
    var myNavSet = require('./video_nav');
    var myVideoPlay = require('./videoConfig');

    var oWindow = $(window);
    var oHeader = $('.js_headerBox');               // 头部
    var oFooter = $('.js_footer');                  // 底部
    var oContain = $('.js_contain');                // 页面内容区域
    var aAllComment = $('.js_allCommentListBox');               // 评论方面的大盒子
    var aCommentScroll = $('.js_allCommentList');               // 评论列表
    var aSubmitBtn = $('.js_submitCommentBtn');                 // 提交按钮
    var oVideoIntro = $('.js_videoIntro');                      // 简介信息
    var oIntroBtn = $('.js_introBtn');                          // 简介按钮
    var openCollectionList = $('.js_openCollectionList');       // 显示全部按钮操作
    var oCollectionList = $('.collectionList');                 // 集数列表
    var resizeTimer = null;
    var oPlayerCenter = $(".js_playerCenter");
    var oHideAllBtn = $(".js_hideAllBtn");

    var aDataUrl =  'static_v4/js/dataJson/goodsData.json'; //请求评论列表 url

    oHeader.on("touchmove",function(e) {e.preventDefault()});
    oFooter.on("touchmove",function(e) {e.preventDefault()});


    var playerVideo = $('.js_playVideo');                                   // 播放器容器



    module.exports = {
        init: function(data,names) {
            myNavSet.SetVideoNav(data, names);
            // myVideo.ddjVideo(oPlayerCenter.eq(0), 'auto');
            myVideoPlay.videoSet('js_videoPlay');

            // aGetData.getAnimeComment(function () {});
            animeCommentObj.submitEvent();
            animeCommentObj.scrollData();
            animeCommentObj.sfddjInit(true);

            // 页面尺寸修改
            oWindow.on('resize',function() {
                if (resizeTimer) {
                    clearTimeout(resizeTimer)
                }
                resizeTimer = setTimeout(function(){
                    animeCommentObj.sfddjInit(true);
                }, 400);
            });

        }
    };

    //数据请求
    var aGetData = {
        getDataNum : [1], //限定请求数据数量的关卡
        getAnimeComment : function (fn) {
            G_JSON_GET(aDataUrl,{},function (data) {
                var getData = data.goodsNew1;
                var shtml = commentHtml.oneCommentHtml(getData);
                aAllComment.append(shtml);
                // myCollection.connetProSwiper();
                if(fn)fn();
            },function () {
                //start
            },function () {
                //end
            })
        }
    }

    // 对象事件
    var animeCommentObj = {
        commentData:{}, //存储要提交评论的内容对象
        sfddjInit: function (bOff) {
            // bOff true 执行下面方法
            if(bOff) {
                oContain.css({
                    'padding-top': oHeader.outerHeight(true),
                    'padding-bottom' : oFooter.outerHeight(true)
                });
            }
        },

        //提交事件
        submitEvent : function () {
            //点击提交按钮
            aSubmitBtn.hammer().on('tap',function () {
                var time = new Date();
                animeCommentObj.commentData.time=time; //提交事件
                animeCommentObj.commentData.text=$('.js_animeCommentText').val();  //评论内容
                aAllComment.prepend(commentHtml.submitHtml(animeCommentObj.commentData));  //数据放在评论列表前面
                $('.js_animeCommentText').val(''); // 清空评论输入的标签

            });
            // 简介展开
            oIntroBtn.hammer().on('tap',function () {
                var _iconStyle = $(this).find('.js_iconStyle');
                if(_iconStyle.hasClass('rotate180')) {
                    _iconStyle.removeClass('rotate180');
                    oVideoIntro.css({'height': 0});
                }
                else {
                    _iconStyle.addClass('rotate180');
                    oVideoIntro.css({'height': 'auto'});
                }
            });
            // 显示全部
            openCollectionList.on('click',function (e) {
                $(this).addClass('active');
                oCollectionList.find('ul').css({'height': 'auto'});
                e.stopPropagation();
            });

            oHideAllBtn.on('click',function (e) {
                openCollectionList.removeClass('active');
                oCollectionList.find('ul').css({'height': '14.7rem'});
                e.stopPropagation();
            });

        },

        //滚动加载
        scrollData:function () {
            // aAllComment.off('scroll');
            aCommentScroll.on('scroll',function () {
                var $this = this;
                var scrollTop = $this.scrollTop;
                var minHeight = 500;
                // console.log(scrollTop);
                if(aAllComment.height()-scrollTop < minHeight){
                    console.log(aGetData.getDataNum);
                    if(aGetData.getDataNum.length == 4){
                        myPub.TipLayer_noShade('没有更多数据了','background:rgba(0,0,0,.8);color:#fff;min-width:55%;',function () {});
                        return;
                    }
                   /* aGetData.getAnimeComment(function () {
                        aGetData.getDataNum.push(1);
                    })*/
                }
            })
        }
    };

    //html拼接
    var commentHtml = {
        oneCommentHtml : function (data) { // 评论列表的内容 html
            var shtml = '';

            for(var i =0; i<data.length; i++){
                shtml +=
                    '<div class="eachCommentDet">'+
                    '    <div class="eachCommentDetHead HBox">'+
                    '        <div class="myAvatarPic">'+
                    '            <figure><img src="static_v4/image/flower5.jpg" alt=""></figure>'+
                    '        </div>'+
                    '        <div class="commentUserInfo Bflex1">'+
                    '            <p class="commentUserName">秋果秋果</p>'+
                    '            <p class="commentUserTime">2017-10-32</p>'+
                    '        </div>'+
                    '        <div class="commentGreatNum VBox BoxCenter">'+
                    '            <p class="greatNum js_getGreatNum">'+
                    '                <span class="iconStyle icon-goods"></span>'+
                    '                <span class="verMid itComGreatNum js_greatNum">25566</span>'+
                    '            </p>'+
                    '        </div>'+
                    '    </div>'+
                    '    <div class="eachCommentDetCon">'+
                    '        <p class="eachCommentDetConText">我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论我要评论。</p>'+
                    '    </div>'+
                    ' </div>';
            }

            return shtml;

        },

        submitHtml : function (data) { // 单个评论的内容html
            var shtml = '';
            shtml =
                '<div class="eachCommentDet">'+
                '    <div class="eachCommentDetHead HBox">'+
                '        <div class="myAvatarPic">'+
                '            <figure><img src="static_v4/image/flower5.jpg" alt=""></figure>'+
                '        </div>'+
                '        <div class="commentUserInfo Bflex1">'+
                '            <p class="commentUserName">秋果秋果</p>'+
                '            <p class="commentUserTime">'+myPub.FormatDateTime(data.time,"minDay")+'</p>'+
                '        </div>'+
                '        <div class="commentGreatNum VBox BoxCenter">'+
                '            <p class="greatNum js_getGreatNum">'+
                '                <span class="iconStyle icon-goods"></span>'+
                '                <span class="verMid itComGreatNum js_greatNum">25566</span>'+
                '            </p>'+
                '        </div>'+
                '    </div>'+
                '    <div class="eachCommentDetCon">'+
                '        <p class="eachCommentDetConText">'+data.text+'</p>'+
                '    </div>'+
                ' </div>';
            return shtml;

        }

    }



})